package com.neusoft.neu24.his.hisapp;

import com.neusoft.neu24.his.hisapp.entity.Patient;
import com.neusoft.neu24.his.hisapp.service.IPatientService;
import com.neusoft.neu24.his.hisapp.service.impl.PatientServiceImpl;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class HelloApplication_TableView extends Application {

    private IPatientService  patientService = new PatientServiceImpl();

    @Override
    public void start(Stage primaryStage) throws IOException {
        TableView<Patient> tblItems = new TableView<>();
        TableColumn<Patient, String>  nameColumn = new TableColumn<>("姓名");
        TableColumn<Patient, String>  sexColumn = new TableColumn<>("性别");
        TableColumn<Patient, String>  ageColumn = new TableColumn<>("年龄");
        TableColumn<Patient, String>  statusColumn = new TableColumn<>("状态");

        nameColumn.setCellValueFactory( new PropertyValueFactory("name") );
        sexColumn.setCellValueFactory( new PropertyValueFactory("sex") );
        ageColumn.setCellValueFactory( new PropertyValueFactory("age") );
        statusColumn.setCellValueFactory( new PropertyValueFactory("status") );

        tblItems.getColumns().addAll(nameColumn,sexColumn,ageColumn,statusColumn);

        List<Patient>  patientsList = patientService.selectAllPatient();

        tblItems.getItems().addAll(patientsList);

        HBox hBox =new HBox();

        Button button =new Button(" Clear ");
        button.setOnAction( event -> {
            tblItems.getItems().clear();
        });


        Button buttonadd =new Button(" Addd ");
        buttonadd.setOnAction( event -> {
            tblItems.getItems().add( new Patient("18","张三","男","正常") );
        });

        hBox.getChildren().addAll(button , buttonadd);

        VBox vbox = new VBox( tblItems,hBox );
        vbox.setPadding( new Insets(10) );
        vbox.setSpacing( 10 );

        Scene scene = new Scene(vbox , 867 , 686);

        primaryStage.setTitle("TableSelectApp");
        primaryStage.setScene( scene );
        primaryStage.setHeight( 667 );
        primaryStage.setWidth( 867 );
        primaryStage.show();


    }
    public static void main(String[] args) {
        launch();
    }
}